package com.cfec.ipoth_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfec.ipoth_service.domain.User;
import com.cfec.ipoth_service.service.UserService;
import com.cfec.ipoth_service.mapper.UserMapper;
import com.cfec.ipoth_service.util.ResultData;
import com.cfec.ipoth_service.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author diyu
* @description 针对表【user(用户信息表)】的数据库操作Service实现
* @createDate 2025-04-19 17:26:32
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{


    @Autowired
    UserMapper userMapper;

    @Autowired
    TokenUtil tokenUtil;

    @Override
    public List<User> select1() {
        return userMapper.selectList(null);
    }

    @Override
    public ResultData select(User user) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>();
        queryWrapper.eq("user_account", user.getUserAccount())
                .eq("user_password", user.getUserPassword());
        User user1 = userMapper.selectOne(queryWrapper);
        if (user1 != null) {
            // 登录成功
            String token = new TokenUtil().createToken(user1);
            return new ResultData(200, "登录成功", token);
        } else {
            // 登录失败
            return new ResultData(501, "登陆失败", null);

        }

    }

}




